/******************************************************************************
 * Copyright 2024 zhangcong. All Rights Reserved.
 *****************************************************************************/

#include "business/recordbusiness/record_manager.h"
#include "business/recordbusiness/storetask_manager.h"
#include "common/common_log.h"
#include "zmq.h"
#include <thread>
#include <unistd.h>

#define MAX_BUFF_LEN 5*1024

static void AssignSensorData(const figureData &figure, const rawData &raw,
                             SensorDataInfo::figureInfo &sensorInfo) {
  sensorInfo.rawValue = raw.rawValue;
  sensorInfo.absAverageValue = figure.absAverageValue;
  sensorInfo.averageValue = figure.averageValue;
  sensorInfo.kurtosis = figure.kurtosis;
  sensorInfo.mainAmp = figure.mainAmp;
  sensorInfo.mainFrequency = figure.mainFrequency;
  sensorInfo.margin = figure.margin;
  sensorInfo.maxValue = figure.maxValue;
  sensorInfo.minValue = figure.minValue;
  sensorInfo.peakFactor = figure.peakFactor;
  sensorInfo.peakValue = figure.peakValue;
  sensorInfo.pulseFactor = figure.pulseFactor;
  sensorInfo.standardDeviation = figure.standardDeviation;
  sensorInfo.variance = figure.variance;
  sensorInfo.waveFactor = figure.waveFactor;
}

void figfunc() {
    void *context = zmq_init(1);
    void *sub = zmq_socket(context, ZMQ_SUB);
    std::string zmqurl = "tcp://192.168.31.169:5555";
    zmq_connect(sub, zmqurl.c_str());
    zmq_setsockopt(sub, ZMQ_SUBSCRIBE, "", 0);
    uint8_t m_SensorBuffer[1024*4] = {0};
    int32_t m_SensorRecvLen = 0;

    Common_Log_e("ListenFigDataFunc start zmqurl:%s\n", zmqurl.c_str());
    while (true)
    {
        uint8_t recvbuf[1024*4] = {0};
        memset(recvbuf, 0, sizeof(recvbuf));
        int32_t nret = zmq_recv(sub, recvbuf, 1024*4, 0);
        if (nret < 0)
        {
            Common_Log_e("sensor zmq recv fail");
            usleep(50000);
            continue;
        }

        printf("recvbuf: \n");
        for (int index = 0; index < nret; index++)
        {
            printf("%x ", recvbuf[index]);
            if (index % 20 == 0)
            {
                printf("\n");
            }
        }

        {
            memset(m_SensorBuffer, 0, sizeof(m_SensorBuffer));
            m_SensorRecvLen = 0;
        }
        memcpy(m_SensorBuffer + m_SensorRecvLen, recvbuf, nret);
        m_SensorRecvLen += nret;

        // 解析recvbuf
        uint8_t leftSensorBuffer[1024*4] = {0};
        int32_t leftBufferLen = 0;
        std::string mccaddr;
        SensorProtoManager sensorMgr;
        int32_t ret = sensorMgr.DeSerializeFigureData(m_SensorBuffer, m_SensorRecvLen, leftSensorBuffer, leftBufferLen, "1", mccaddr);
        if (ret < 0)
        {
            Common_Log_e("proto DeSerialize error!!!");
            usleep(50000);
            continue;
        }
        memset(m_SensorBuffer, 0, sizeof(m_SensorBuffer));
        memcpy(m_SensorBuffer, leftSensorBuffer, leftBufferLen);

        SensorData objData;
        sensorMgr.GetSensorData(mccaddr, objData);
        uint16_t chanparam = objData.chanparam;

        int32_t circleSize = objData.figureDataList.size();
        printf("figureDataList size:%d\n", circleSize);
        // for (int32_t index = 0; index < circleSize; index++)
        // {
        //     SensorDataInfo::CommonSensor sensorData;
        //     memset(&sensorData, 0, sizeof(sensorData));
        //     sensorData.timestamp = objData.timems;

        //     std::map<int32_t, figureData> figItem = objData.figureDataList[index];
        //     std::map<int32_t, rawData> rawItem = objData.rawDataList[index];

        //     int32_t itemIndex = 0;
        //     for (int32_t typeIndex = SensorDataInfo::CHAN_ACCX; typeIndex <= SensorDataInfo::CHAN_ACCZ; typeIndex++)
        //     {
        //         if (chanparam & (0x1 << typeIndex))
        //         {
        //             // figureData figdata = figItem[itemIndex];
        //             figureData figdata = {0};
        //             rawData rawdata = rawItem[itemIndex];
        //             switch (typeIndex)
        //             {
        //             case SensorDataInfo::CHAN_ACCX:
        //             {
        //                 AssignSensorData(figdata, rawdata, sensorData.accX);
        //                 break;
        //             }
        //             case SensorDataInfo::CHAN_ACCY:
        //             {
        //                 AssignSensorData(figdata, rawdata, sensorData.accY);
        //                 break;
        //             }
        //             case SensorDataInfo::CHAN_ACCZ:
        //             {
        //                 AssignSensorData(figdata, rawdata, sensorData.accZ);
        //                 break;
        //             }
        //             }

        //             itemIndex++;
        //         }
        //     }

        //     // 根据sn确定文件进行保存
        //     std::stringstream sensorType;
        //     sensorType << std::hex << objData.sn;
        //     printf("sensorType:%s ", sensorType.str());
        //     // addSensorData(sensorData, sensorType.str());
        // }

        usleep(1000000);
    }

    zmq_close(sub);
    zmq_term(context);
}

void rawfunc() {
  void *context = zmq_ctx_new();
  void *sub = zmq_socket(context, ZMQ_SUB);
  std::string zmqurl = "tcp://192.168.31.207:55552";
  // zmq_connect(sub, zmqurl.c_str());
  char addr[100] = {0};
  sprintf(addr, "tcp://%s:%s", "192.168.31.207", "55552");
  int rc = zmq_connect(sub, addr);
  if (rc != 0) {
    printf("zmq_connect fail!\n");
    return;
  }
  rc = zmq_setsockopt(sub, ZMQ_SUBSCRIBE, "", 0);
  if (rc != 0) {
    printf("zmq_setsockopt fail!\n");
    return;
  }

  uint32_t m_sensorRecvLen = 0;
  uint8_t m_sensorBuffer[MAX_BUFF_LEN] = {0};
  while (true) 
  {
    sleep(1);
    printf("zmqurl **new**:%s start\n", addr);
    char recvbuf[1024] = {0};
    memset(recvbuf, 0, sizeof(recvbuf));

    zmq_msg_t msg;
    bzero(&msg, sizeof(msg));
    zmq_msg_init(&msg);
    zmq_msg_recv(&msg, sub, 0); // 1非阻塞，0阻塞
    void *message = zmq_msg_data((zmq_msg_t *)&msg);
    size_t size = zmq_msg_size(&msg);
    printf("recv size:%d\n", size);

    // if (size + m_sensorRecvLen > MAX_BUFF_LEN)
    {
      memset(m_sensorBuffer, 0, sizeof(m_sensorBuffer));
      m_sensorRecvLen = 0;
    }
    memcpy(m_sensorBuffer + m_sensorRecvLen, message, size);
    m_sensorRecvLen = size;

    for (int index = 0; index < m_sensorRecvLen; index++) {
      printf("%x ", m_sensorBuffer[index]);
      if (index % 20 == 0) {
        printf("\n");
      }
    }

    // 解析recvbuf
    uint8_t leftSensorBuffer[MAX_BUFF_LEN] = {0};
    int32_t leftBufferLen = 0;
    SensorProtoManager sensorMgr;
    std::string mccaddr;
    int32_t ret = sensorMgr.DeSerializeRawData(m_sensorBuffer, m_sensorRecvLen,
                                               leftSensorBuffer, leftBufferLen, "1", mccaddr);
    if (ret < 0) {
      Common_Log_e("proto DeSerializeFigureData error!!!");
      continue;
    }
    memset(m_sensorBuffer, 0, sizeof(m_sensorBuffer));
    memcpy(m_sensorBuffer, leftSensorBuffer, leftBufferLen);

    SensorData objData;
    sensorMgr.GetSensorData(mccaddr, objData);
    uint16_t chanparam = objData.chanparam;

    int circleSize = objData.rawDataList.size();
    int figsize = objData.figureDataList.size();
    int plcsize = objData.plcDataList.size();
    printf("circleSize:%d figsize:%d plcsize:%d\n", circleSize, figsize, plcsize);
    for (int32_t index = 0; index < circleSize; index++) {
      SensorDataInfo::CommonSensor sensorData;
      memset(&sensorData, 0, sizeof(sensorData));
      sensorData.timestamp = objData.timems;

      std::map<int32_t, rawData> rawItem = objData.rawDataList[index];

      int32_t itemIndex = 0;
      for (int32_t typeIndex = SensorDataInfo::CHAN_ACCX;
           typeIndex <= SensorDataInfo::CHAN_ACCZ; typeIndex++) {
        if (chanparam & (0x1 << typeIndex)) {
          figureData figdata = {0};
          rawData rawdata = rawItem[itemIndex];
          switch (typeIndex) {
          case SensorDataInfo::CHAN_ACCX: {
            AssignSensorData(figdata, rawdata, sensorData.accX);
            break;
          }
          case SensorDataInfo::CHAN_ACCY: {
            AssignSensorData(figdata, rawdata, sensorData.accY);
            break;
          }
          case SensorDataInfo::CHAN_ACCZ: {
            AssignSensorData(figdata, rawdata, sensorData.accZ);
            break;
          }
          }

          itemIndex++;
        }
      }

      printf("accX:%lf, accY:%lf, accZ:%lf\n", sensorData.accX.rawValue, sensorData.accY.rawValue, sensorData.accZ.rawValue);
    }
  }

    zmq_close(sub);
    zmq_term(context);
}

void pubfig() {
  uint8_t pubdata[] = {
      0xa5, 0x5a, 0x8a, 0x13, 0x0,  0x0,  0x42, 0x0,  0x15, 0x9,  0x8,  0x0,
      0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0xbd, 0x3f, 0x2,  0xc,  0x0,  0xc0,
      0x7a, 0x44, 0xf,  0x7d, 0x99, 0x9d, 0x6e, 0x91, 0x1,  0x0,  0x0,  0x78,
      0x61, 0x35, 0x0,  0x0,  0x0,  0x3f, 0x13, 0xe6, 0xf4, 0x3e, 0x35, 0x14,
      0x27, 0x3e, 0xcd, 0x43, 0xd4, 0x3e, 0xc8, 0x7f, 0xae, 0x3e, 0xc8, 0x7f,
      0xae, 0x3b, 0xfa, 0xca, 0xde, 0x3d, 0xb3, 0x2b, 0x32, 0xbf, 0x3,  0x54,
      0x38, 0xbe, 0x15, 0x8c, 0xb6, 0x3f, 0x83, 0x27, 0xc1, 0x3f, 0xb8, 0x4c,
      0xfa, 0x3f, 0xbc, 0xd8, 0x6,  0x41, 0x97, 0x65, 0x6f, 0x40, 0x13, 0x9d,
      0x76, 0x3f, 0x9,  0x4f, 0x73, 0x3f, 0x13, 0xe6, 0xf4, 0x3f, 0x8,  0x10,
      0x72, 0x3f, 0x7,  0x98, 0xd2, 0x3e, 0xe1, 0x16, 0xa0, 0x3e, 0xee, 0x2c,
      0x21, 0x3e, 0xf4, 0x17, 0x62, 0x3e, 0xe3, 0x94, 0xa0, 0x3f, 0x6,  0xa9,
      0x92, 0x3e, 0xfb, 0x91, 0x63, 0x3e, 0xe5, 0xc2, 0xe0, 0x3e, 0xe7, 0x51,
      0xa0, 0x3e, 0xcd, 0xc6, 0x1d, 0x3e, 0xad, 0x60, 0x1a, 0x3e, 0xd3, 0x61,
      0x9e, 0x3f, 0x1,  0xe,  0x12, 0x3e, 0xcc, 0x87, 0x1d, 0x3e, 0xbb, 0xb4,
      0x9b, 0x3e, 0xb4, 0xda, 0x1a, 0x3e, 0xe3, 0x94, 0xa0, 0x3e, 0xbf, 0xc1,
      0x5c, 0x3e, 0xdd, 0x9,  0xdf, 0x3e, 0xfa, 0x52, 0x62, 0x3e, 0xae, 0x9f,
      0x1a, 0x3e, 0x99, 0x20, 0x57, 0x3e, 0xd7, 0x1e, 0x9e, 0x3e, 0xdb, 0x2b,
      0x5f, 0x3e, 0xc8, 0x22, 0x53, 0x3e, 0x8c, 0xb,  0x36, 0x3e, 0x35, 0x14,
      0x27, 0x3e, 0x9f, 0xf8, 0x59, 0x3e, 0x78, 0x54, 0x7d, 0x3e, 0xb7, 0x2,
      0x89, 0x3e, 0xd8, 0xf2, 0x68, 0x3e, 0x92, 0x95, 0x5,  0x3e, 0xa7, 0xc0,
      0xfa, 0x3e, 0x6d, 0x1f, 0x19, 0x3e, 0x8c, 0xb,  0x36, 0x3e, 0x95, 0x62,
      0x5e, 0x3e, 0x8a, 0x2c, 0xfb, 0x3e, 0xc0, 0x9,  0xfd, 0x3e, 0xbf, 0x1a,
      0xdf, 0x3e, 0xea, 0x61, 0xe6, 0x3e, 0x94, 0xc2, 0xf5, 0x3e, 0xae, 0x4a,
      0xca, 0x3e, 0x98, 0xcf, 0x20, 0x3e, 0xa7, 0x71, 0x46, 0x3e, 0xee, 0x6e,
      0x12, 0x3e, 0xe8, 0x33, 0xf7, 0x3e, 0xd8, 0x52, 0xff, 0x3e, 0xb8, 0xe0,
      0xc4, 0x3e, 0xd8, 0x3,  0x4a, 0x3e, 0xc5, 0x54, 0xfa};

  uint8_t pubdata1[] = {
      0xa5, 0x5a, 0x8a, 0x13, 0x0,  0x0,  0x3,  0x0,  0x15, 0x9,  0x8,  0x0,
      0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0xbd, 0x3f, 0x2,  0xc,  0x0,  0xc0,
      0x7a, 0x44, 0xf,  0xf3, 0x2d, 0x44, 0x6f, 0x91, 0x1,  0x0,  0x0,  0x68,
      0x64, 0x32, 0x0,  0x0,  0x0,  0xb6, 0x52, 0x1e, 0xab, 0xba, 0x3d, 0x75,
      0x3,  0x3a, 0x3c, 0xa2, 0xe4, 0xb9, 0xf8, 0x40, 0x3b, 0x39, 0xf8, 0x40,
      0x3b, 0x33, 0x88, 0x3,  0x5d, 0x39, 0x83, 0xf2, 0x1d, 0xbf, 0x8d, 0xdb,
      0xea, 0x3f, 0x28, 0x8d, 0xc0, 0x3f, 0x90, 0xf4, 0xdc, 0xbb, 0xbf, 0x55,
      0x15, 0xbb, 0xd8, 0xad, 0xbb, 0x41, 0xbf, 0xc,  0x31, 0x3b, 0xd4, 0x69,
      0xc0, 0xbe, 0x7c, 0xb6, 0xfa, 0x3c, 0xed, 0xdd, 0xe0, 0x3e, 0x21, 0x4b,
      0x5,  0xbd, 0xd1, 0xe3, 0x47, 0xbe, 0x1c, 0x12, 0x45, 0x3e, 0x5,  0x3c,
      0x3c, 0xbf, 0xd,  0x95, 0xa4, 0xbe, 0xd8, 0x74, 0x36, 0xbf, 0x30, 0xa8,
      0x1f, 0xbd, 0xe3, 0x58, 0x91, 0xb9, 0x47, 0x9d, 0xd4, 0xbe, 0xbc, 0x65,
      0x6d, 0x3d, 0xd9, 0xd6, 0x4e, 0xbe, 0xc3, 0xe0, 0xd6, 0x3e, 0x74, 0x38,
      0x24, 0x3d, 0xe0, 0x12, 0x7b, 0x3e, 0x79, 0x35, 0x15, 0xbe, 0xd4, 0x66,
      0xb3, 0x3d, 0xbd, 0x27, 0xe7, 0xbd, 0x2a, 0x5f, 0x91, 0xbe, 0x7c, 0x17,
      0x5c, 0x3e, 0xb9, 0x65, 0x3e, 0x3d, 0xca, 0xdf, 0x7c, 0x3e, 0x9f, 0xd4,
      0xed, 0x3d, 0xdc, 0x54, 0xc6, 0x3e, 0x31, 0xc,  0x48, 0x3e, 0x2c, 0xb0,
      0x59, 0x3d, 0xf0, 0xc2, 0x3e, 0x3d, 0xcd, 0xe2, 0xc3, 0x3e, 0x2b, 0x71,
      0x82, 0xbc, 0xe8, 0x9c, 0x27, 0x3d, 0x85, 0xa6, 0x1e, 0x3e, 0x2e, 0x8e,
      0x9b, 0x3e, 0x20, 0xdb, 0x61, 0x3d, 0x8a, 0xa1, 0x79, 0x3e, 0x83, 0x7e,
      0x13, 0x3e, 0x50, 0x2f, 0x40, 0x3e, 0x48, 0xb6, 0x37, 0x3d, 0x85, 0xa6,
      0x1e, 0x3d, 0xab, 0x3,  0x47, 0x3d, 0x4,  0xc9, 0xa9, 0x3d, 0x7c, 0x5a,
      0x2c, 0x3c, 0xdc, 0xbd, 0x20, 0x3d, 0x99, 0x93, 0x89, 0x3e, 0x1c, 0x7f,
      0x72, 0x3d, 0xc0, 0x2f, 0x89, 0x3d, 0xe6, 0xcb, 0x89, 0x3d, 0x74, 0xe1,
      0x24, 0x3d, 0xc1, 0x6e, 0x60, 0xbc, 0xc0, 0xc1, 0x51};

  uint8_t pubdata2[] = {
      0xa5, 0x5a, 0x67, 0x0,  0x0,  0x0,  0xd9, 0x1d, 0x45, 0x1,  0x0,  0x0,
      0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0xbd, 0x3f, 0x2,  0xc,  0x0,  0xc0,
      0x7a, 0x44, 0x3,  0xe,  0x2e, 0x44, 0x6f, 0x91, 0x1,  0x0,  0x0,  0x78,
      0x61, 0x35, 0x0,  0x0,  0x0,  0x3f, 0x33, 0xa1, 0x76, 0xbe, 0x8d, 0xcd,
      0x2f, 0x3f, 0x7a, 0x88, 0xe,  0x3e, 0x50, 0xc3, 0xfe, 0x3e, 0xd5, 0x5c,
      0x74, 0x3e, 0x36, 0xcf, 0xae, 0x3e, 0xd8, 0x55, 0x14, 0xbf, 0xfb, 0x68,
      0x6f, 0x3d, 0x2b, 0x8e, 0x75, 0x3f, 0x90, 0x19, 0xb8, 0x3f, 0xbf, 0x72,
      0x92, 0x3f, 0xd7, 0x87, 0x5c, 0x41, 0x97, 0x65, 0x6f, 0x41, 0x61, 0xbf,
      0x28, 0xbe, 0x89, 0x1f, 0xf,  0xbe, 0x65, 0xef, 0xe3, 0xbe, 0x6e, 0xc,
      0xa3, 0xbe, 0x7e, 0xe5, 0xe1, 0xbe, 0x5c, 0x93, 0xa4, 0xbe, 0x5c, 0x93,
      0xa4, 0xbe, 0x4b, 0x1a, 0xa6, 0xbe, 0x14, 0x30, 0xac, 0xbe, 0x47, 0xfb,
      0xe7, 0xbe, 0x62, 0x31, 0x64, 0xbe, 0x12, 0xf1, 0x2c, 0xbe, 0xe,  0x92,
      0xed, 0xbe, 0x2d, 0x26, 0xa9, 0xbe, 0x3f, 0xdf, 0x27, 0xbe, 0x7e, 0x46,
      0x21, 0xbe, 0x66, 0x8f, 0xa3, 0xbe, 0x42, 0xfd, 0xe7, 0xbe, 0x8d, 0xcd,
      0x2f, 0xbe, 0x65, 0xef, 0xe3, 0xbe, 0x69, 0xe,  0xa3, 0xbe, 0x84, 0xc0,
      0xd0, 0xbe, 0x4c, 0x5a, 0x26, 0xbe, 0x35, 0x43, 0x69, 0xbe, 0x5a, 0xb4,
      0x65, 0xbe, 0x28, 0x28, 0xaa, 0xbe, 0x6a, 0xed, 0xe3, 0xbe, 0x4e, 0x39,
      0x66, 0x3f, 0x2e, 0xcb, 0x9e, 0x3f, 0x11, 0x50, 0xc6, 0x3f, 0xf,  0xe9,
      0x67, 0x3f, 0x17, 0xb5, 0xec, 0x3f, 0x1a, 0x34, 0xcf, 0x3f, 0x1e, 0xba,
      0xca, 0x3f, 0x1f, 0x82, 0x71, 0x3f, 0x23, 0x40, 0xc5, 0x3f, 0x26, 0xf,
      0x84, 0x3f, 0x23, 0x40, 0xc5, 0x3f, 0x23, 0x40, 0xc5, 0x3f, 0x2b, 0xad,
      0x3,  0x3f, 0x27, 0xee, 0xae, 0x3f, 0xd,  0x1a, 0xa8, 0x3f, 0xe,  0x32,
      0x2b, 0x3f, 0x27, 0xc6, 0xc0, 0x3f, 0x22, 0xc8, 0xfa, 0x3f, 0x15, 0xfe,
      0xb0, 0x3f, 0x2c, 0x9c, 0x98, 0x3f, 0x2a, 0x95, 0x7f, 0x3f, 0x33, 0xa1,
      0x76, 0x3f, 0x2c, 0x74, 0xaa, 0x3f, 0x28, 0x16, 0x9d, 0x3f, 0x2d, 0xdc,
      0x9,  0x3f, 0x2f, 0x1b, 0x7b, 0x3f, 0x16, 0x4e, 0x8c};

  uint8_t pubdata3[] = {
      0xa5, 0x5a, 0x6c, 0x0,  0x0,  0x0,  0xbc, 0x0,  0x45, 0x1,  0x1,  0x0,
      0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0xbd, 0x3f, 0x2,  0xc,  0x0,  0xc0,
      0x7a, 0x44, 0x2,  0xf8, 0x6f, 0xc4, 0x72, 0x91, 0x1,  0x0,  0x0,  0x78,
      0x61, 0x69, 0x0,  0x0,  0x0,  0x41, 0xf,  0x69, 0x5a, 0xc1, 0x8d, 0x9d,
      0x75, 0x41, 0xd5, 0x52, 0x22, 0xc0, 0x85, 0x9d, 0xe8, 0x40, 0xd0, 0x75,
      0xea, 0x42, 0x4f, 0x39, 0xe6, 0x40, 0xe6, 0x53, 0x5d, 0xbf, 0x38, 0x60,
      0xb7, 0xbd, 0xcb, 0xd3, 0x6a, 0x3f, 0xa3, 0x80, 0x27, 0x3f, 0x89, 0xe0,
      0x6b, 0x3f, 0xb0, 0x1d, 0xd3, 0x41, 0x18, 0xd6, 0x8d, 0x43, 0xe1, 0x27,
      0xd9, 0xc1, 0x25, 0xbf, 0x3,  0xc1, 0x27, 0x35, 0x7,  0xc1, 0x28, 0xe4,
      0x65, 0xc1, 0x28, 0x80, 0xa8, 0xc1, 0x23, 0x81, 0x85, 0xc1, 0x25, 0x6c,
      0xba, 0xc1, 0x2d, 0xe8, 0x84, 0xc1, 0x30, 0xa7, 0xab, 0xc1, 0x30, 0xcd,
      0x12, 0xc1, 0x2d, 0x75, 0xd1, 0xc1, 0x2a, 0xb4, 0x2c, 0xc1, 0x2a, 0x4b,
      0x73, 0xc1, 0x24, 0x44, 0x2,  0xc1, 0x1e, 0xf5, 0x15, 0xc1, 0x13, 0x15,
      0x93, 0xc1, 0x8,  0xdd, 0xf4, 0xc0, 0xfa, 0xec, 0x44, 0xc0, 0xed, 0x17,
      0x94, 0xc0, 0xd6, 0xe2, 0x87, 0xc0, 0xb6, 0xaf, 0x35, 0xc0, 0xa5, 0x49,
      0xeb, 0xc0, 0x8e, 0x7,  0x93, 0xc0, 0x78, 0x69, 0x27, 0xc0, 0x43, 0xd0,
      0x90, 0xc0, 0x15, 0xb9, 0x97, 0xc0, 0x29, 0x70, 0x52, 0xc0, 0x36, 0x9b,
      0x74, 0xc0, 0x1f, 0x59, 0x1d, 0xc0, 0x18, 0x41, 0xe3, 0xbf, 0xf1, 0x52,
      0x51, 0xbf, 0xea, 0xee, 0x9e, 0xc0, 0x17, 0xf2, 0x19, 0xc0, 0x26, 0x84,
      0x49, 0xc0, 0x20, 0x16, 0x9d, 0xc0, 0x1b, 0xcd, 0x80, 0xc0, 0x7,  0x59,
      0x45, 0xc0, 0x3,  0x91, 0xd0, 0xc0, 0xe,  0xfc, 0x21, 0xc0, 0xe,  0xa2,
      0x5d, 0xbf, 0xe8, 0x20, 0x81, 0xbf, 0xa9, 0xa2, 0x94, 0xbf, 0x73, 0x45,
      0xc9, 0xbf, 0x69, 0x4c, 0x80, 0xbf, 0x33, 0xb0, 0x97, 0xbf, 0x0,  0x6b,
      0x1c, 0xbf, 0x35, 0x3f, 0x8b, 0xbe, 0x67, 0x4a, 0x8b, 0x3e, 0xd7, 0xab,
      0xac, 0x3e, 0xdd, 0xe7, 0x7a, 0xbe, 0xae, 0xdd, 0x67, 0xbf, 0x83, 0x10,
      0x8b, 0xbf, 0x8b, 0xb6, 0xb9, 0xbf, 0xb2, 0x48, 0xc1, 0xbf, 0xbb, 0x3e,
      0xb9, 0xbf, 0xdd, 0xaf, 0x89, 0xbf, 0xc2, 0xcd, 0xa2, 0xbf, 0xb8, 0x84,
      0x8f, 0xbf, 0x23, 0xa3, 0x66, 0xbf, 0x5,  0xdf, 0x70, 0x3f, 0xb6, 0x68,
      0x6a, 0x40, 0x84, 0x1c, 0xdc, 0x40, 0x9d, 0x38, 0xf5, 0x40, 0xe9, 0xea,
      0x53, 0x41, 0x1,  0x9e, 0xa3, 0x41, 0x6,  0x96, 0x4b, 0x41, 0x2,  0x40,
      0xb6, 0x41, 0xf,  0x69, 0x5a, 0x41, 0xd,  0xb2, 0x82, 0x41, 0x8,  0x39,
      0x31, 0x41, 0x1,  0x35, 0xea, 0x40, 0xee, 0xc4, 0xf,  0x40, 0xee, 0xc9,
      0xc,  0x40, 0xdf, 0x79, 0x5a, 0x40, 0xc8, 0x0,  0x28, 0x40, 0xb2, 0x5b,
      0xba, 0x40, 0xa2, 0xbc, 0x3f, 0x40, 0x78, 0xa4, 0x37, 0x3f, 0xdc, 0xaa,
      0xa8, 0x3e, 0xca, 0x94, 0x7d, 0x3e, 0x8d, 0x2d, 0xd3, 0xbe, 0x9b, 0x8a,
      0x6a, 0xbf, 0xdd, 0x4b, 0xcc, 0xc0, 0x2b, 0xee, 0xa4, 0xc0, 0x82, 0xf7,
      0x6,  0xc0, 0xc0, 0x8a, 0x92, 0xc0, 0xd5, 0x5d, 0x8d, 0xc0, 0xf8, 0x50,
      0x6,  0xc1, 0x13, 0x88, 0x46, 0xc1, 0x27, 0x5a, 0x6e, 0xc1, 0x35, 0x92,
      0xdb, 0xc1, 0x41, 0x60, 0xe9, 0xc1, 0x4e, 0xd1, 0xdc, 0xc1, 0x57, 0xe5,
      0xbf, 0xc1, 0x68, 0x22, 0x51, 0xc1, 0x77, 0xb0, 0x58, 0xc1, 0x7f, 0x55,
      0xb2, 0xc1, 0x7f, 0xe8, 0xcf, 0xc1, 0x82, 0x3,  0xc5, 0xc1, 0x85, 0xc9,
      0xfa, 0xc1, 0x88, 0x3d, 0x14, 0xc1, 0x89, 0xe4, 0xf7, 0xc1, 0x8b, 0x47,
      0x8,  0xc1, 0x8b, 0xe2, 0xdf, 0xc1, 0x8d, 0x9,  0x19, 0xc1, 0x8d, 0x9d,
      0x75};

  uint8_t pubdata4[] = {
      0xa5, 0x5a, 0x6c, 0x0,  0x0,  0x0,  0xbc, 0x0,  0x45, 0x1,  0x1,  0x0,
      0x0,  0x0,  0x0,  0x0,  0x0,  0x0,  0xbd, 0x3f, 0x2,  0xc,  0x0,  0xc0,
      0x7a, 0x44, 0x2,  0xf8, 0x6f, 0xc4, 0x72, 0x91, 0x1,  0x0,  0x0,  0x79,
      0x76, 0x69, 0x0,  0x0,  0x0,  0xbd, 0x2a, 0xff, 0x68, 0xbf, 0xc3, 0x28,
      0xf1, 0x3f, 0xbd, 0xd0, 0xf6, 0xbf, 0x3f, 0x89, 0x3a, 0x3f, 0x3f, 0x89,
      0x3a, 0x3d, 0x97, 0xf1, 0x19, 0x3e, 0x8b, 0x75, 0x43, 0x3f, 0x33, 0x12,
      0xab, 0x3d, 0x8b, 0x3,  0x78, 0x3f, 0x88, 0x37, 0xe4, 0xbd, 0x56, 0xc2,
      0xa7, 0xbd, 0x64, 0x8c, 0x97, 0x41, 0xee, 0x56, 0x2e, 0x41, 0x1a, 0xfe,
      0x96, 0xc1, 0x25, 0xbf, 0x3,  0xc1, 0x27, 0x35, 0x7,  0xc1, 0x28, 0xe4,
      0x65, 0xc1, 0x28, 0x80, 0xa8, 0xc1, 0x23, 0x81, 0x85, 0xc1, 0x25, 0x6c,
      0xba, 0xc1, 0x2d, 0xe8, 0x84, 0xc1, 0x30, 0xa7, 0xab, 0xc1, 0x30, 0xcd,
      0x12, 0xc1, 0x2d, 0x75, 0xd1, 0xc1, 0x2a, 0xb4, 0x2c, 0xc1, 0x2a, 0x4b,
      0x73, 0xc1, 0x24, 0x44, 0x2,  0xc1, 0x1e, 0xf5, 0x15, 0xc1, 0x13, 0x15,
      0x93, 0xc1, 0x8,  0xdd, 0xf4, 0xc0, 0xfa, 0xec, 0x44, 0xc0, 0xed, 0x17,
      0x94, 0xc0, 0xd6, 0xe2, 0x87, 0xc0, 0xb6, 0xaf, 0x35, 0xc0, 0xa5, 0x49,
      0xeb, 0xc0, 0x8e, 0x7,  0x93, 0xc0, 0x78, 0x69, 0x27, 0xc0, 0x43, 0xd0,
      0x90, 0xc0, 0x15, 0xb9, 0x97, 0xc0, 0x29, 0x70, 0x52, 0xc0, 0x36, 0x9b,
      0x74, 0xc0, 0x1f, 0x59, 0x1d, 0xc0, 0x18, 0x41, 0xe3, 0xbf, 0xf1, 0x52,
      0x51, 0xbf, 0xea, 0xee, 0x9e, 0xc0, 0x17, 0xf2, 0x19, 0xc0, 0x26, 0x84,
      0x49, 0xc0, 0x20, 0x16, 0x9d, 0xc0, 0x1b, 0xcd, 0x80, 0xc0, 0x7,  0x59,
      0x45, 0xc0, 0x3,  0x91, 0xd0, 0xc0, 0xe,  0xfc, 0x21, 0xc0, 0xe,  0xa2,
      0x5d, 0xbf, 0xe8, 0x20, 0x81, 0xbf, 0xa9, 0xa2, 0x94, 0xbf, 0x73, 0x45,
      0xc9, 0xbf, 0x69, 0x4c, 0x80, 0xbf, 0x33, 0xb0, 0x97, 0xbf, 0x0,  0x6b,
      0x1c, 0xbf, 0x35, 0x3f, 0x8b, 0xbe, 0x67, 0x4a, 0x8b, 0x3e, 0xd7, 0xab,
      0xac, 0x3e, 0xdd, 0xe7, 0x7a, 0xbe, 0xae, 0xdd, 0x67, 0xbf, 0x83, 0x10,
      0x8b, 0xbf, 0x8b, 0xb6, 0xb9, 0xbf, 0xb2, 0x48, 0xc1, 0xbf, 0xbb, 0x3e,
      0xb9, 0xbf, 0xdd, 0xaf, 0x89, 0xbf, 0xc2, 0xcd, 0xa2, 0xbf, 0xb8, 0x84,
      0x8f, 0xbf, 0x23, 0xa3, 0x66, 0xbf, 0x5,  0xdf, 0x70, 0x3f, 0xb6, 0x68,
      0x6a, 0x40, 0x84, 0x1c, 0xdc, 0x40, 0x9d, 0x38, 0xf5, 0x40, 0xe9, 0xea,
      0x53, 0x41, 0x1,  0x9e, 0xa3, 0x41, 0x6,  0x96, 0x4b, 0x41, 0x2,  0x40,
      0xb6, 0x41, 0xf,  0x69, 0x5a, 0x41, 0xd,  0xb2, 0x82, 0x41, 0x8,  0x39,
      0x31, 0x41, 0x1,  0x35, 0xea, 0x40, 0xee, 0xc4, 0xf,  0x40, 0xee, 0xc9,
      0xc,  0x40, 0xdf, 0x79, 0x5a, 0x40, 0xc8, 0x0,  0x28, 0x40, 0xb2, 0x5b,
      0xba, 0x40, 0xa2, 0xbc, 0x3f, 0x40, 0x78, 0xa4, 0x37, 0x3f, 0xdc, 0xaa,
      0xa8, 0x3e, 0xca, 0x94, 0x7d, 0x3e, 0x8d, 0x2d, 0xd3, 0xbe, 0x9b, 0x8a,
      0x6a, 0xbf, 0xdd, 0x4b, 0xcc, 0xc0, 0x2b, 0xee, 0xa4, 0xc0, 0x82, 0xf7,
      0x6,  0xc0, 0xc0, 0x8a, 0x92, 0xc0, 0xd5, 0x5d, 0x8d, 0xc0, 0xf8, 0x50,
      0x6,  0xc1, 0x13, 0x88, 0x46, 0xc1, 0x27, 0x5a, 0x6e, 0xc1, 0x35, 0x92,
      0xdb, 0xc1, 0x41, 0x60, 0xe9, 0xc1, 0x4e, 0xd1, 0xdc, 0xc1, 0x57, 0xe5,
      0xbf, 0xc1, 0x68, 0x22, 0x51, 0xc1, 0x77, 0xb0, 0x58, 0xc1, 0x7f, 0x55,
      0xb2, 0xc1, 0x7f, 0xe8, 0xcf, 0xc1, 0x82, 0x3,  0xc5, 0xc1, 0x85, 0xc9,
      0xfa, 0xc1, 0x88, 0x3d, 0x14, 0xc1, 0x89, 0xe4, 0xf7, 0xc1, 0x8b, 0x47,
      0x8,  0xc1, 0x8b, 0xe2, 0xdf, 0xc1, 0x8d, 0x9,  0x19, 0xc1, 0x8d, 0x9d,
      0x75};

  void *context = zmq_ctx_new();
  void *pub = zmq_socket(context, ZMQ_PUB);
  char addr[100] = {0};
  sprintf(addr, "tcp://%s:%s", "*", "55553");
  int rc = zmq_bind(pub, addr);
  if (rc != 0) {
    printf("zmq_bind fail!\n");
    return;
  }

  while(1) {
    int32_t rc = zmq_send(pub, pubdata3, sizeof(pubdata3), 0);
     rc = zmq_send(pub, pubdata4, sizeof(pubdata4), 0);
     sleep(1);
  }
}

void test_data_upload()
{
    StoreTaskInfo info;
                info.upload_data = false;
                info.upload_file = true;
                info.coreCpuID = "XXXXZZZZ";
                info.storeCpuID = "SADFWEES";
                info.storeTaskName = "TESTUPLOAD";
                info.zmqIp = "192.168.31.177";
                info.mccAddress = "1";
                info.createTime = "";
                info.startTime = "2024-09-20 08:15:26";
                info.endTime = "2025-12-30 20:15:26";
                info.wsUrl = "ws://180.76.250.75:8088";
                info.minioEndPoint = "http://180.76.250.75:9000";
                info.minioBucketName = "edge-test";
                info.minioAccessKey = "edge";
                info.minioSecretKey = "2xxhfy5ZE7j.vji";
    StoreTaskManager::GetInstance()->AddStoreTask("0073", info);
    StoreTaskManager::GetInstance()->StartStoreTask("0073");
}

int main() {
  // std::thread rawthread(rawfunc);
  // std::thread figthread(figfunc);

  std::thread figpubthread(pubfig);
  test_data_upload();
  while (1) {
    sleep(2);
  }

  return 0;
}